package metro.response;

import metro.cards.Card;
import metro.cards.DurationCard;
import metro.cards.EntranceCard;
import metro.cards.MoneyCard;
import metro.cards.types.CardSpecialType;
import metro.cards.types.CardType;
import metro.tourniquet.Tourniquet;

import java.util.Calendar;

public class Response {
    private boolean success;
    private String message;
    private Card card;
    private Tourniquet tourniquet;
    private Calendar attemptCalendar;
    private Response(boolean status, String message, Card card,Tourniquet tourniquet) {
        this.success = status;
        this.message = message;
        this.card=card;
        this.tourniquet=tourniquet;
        attemptCalendar =Calendar.getInstance();
    }

    public static Response createNegativeTimeResponse(Card card,Tourniquet tourniquet){
        return new Response(false, "Card expired or doesn't activate yet.",card,tourniquet);
    }

    public static Response createPositiveDurationResponse(Calendar current, DurationCard card,Tourniquet tourniquet) {
        return new Response(true, "Card will expired in "+DurationCard.dateDiffInDays(current,card.getExpiredDate())+".",card,tourniquet);
    }

    public static Response createNegativeEntranceResponse(EntranceCard card,Tourniquet tourniquet){
        return new Response(false, "You have 0 trips.",card,tourniquet);
    }

    public static Response createPositiveEntranceResponse(EntranceCard card,Tourniquet tourniquet) {
        return new Response(true, "You have available "+card.getAvailableEntrance()+" trips.",card,tourniquet);
    }



    public static Response createNegativeMoneyResponse(MoneyCard card,Tourniquet tourniquet){
        return new Response(false, "You have "+card.balanceToString()+".",card,tourniquet);
    }

    public static Response createPositiveMoneyResponse(MoneyCard card,Tourniquet tourniquet) {
        return new Response(true, "You have "+card.balanceToString()+".",card,tourniquet);
    }

    public static Response createNegativeCardNotFound(Card card,Tourniquet tourniquet){
        return new Response(false, "Can't find card with such id.",card,tourniquet);
    }

    public boolean isSuccess() {
        return success;
    }

    public String getMessage() {
        return message;
    }

    public long getCardID() {
        return card==null?-1:card.getId();
    }

    public long getTourniquetID(){
        return tourniquet==null?-1:tourniquet.getId();
    }

    public Calendar getAttemptCalendar() {
        return attemptCalendar;
    }

    public CardType getCardType(){
        return card.getType();
    }

    public CardSpecialType getCardSpecialType(){
        return card.getSpecialType();
    }
}